package com.xy.novelmanagement.controller;

import com.xy.model.Comment;
import com.xy.model.PageList;
import com.xy.model.RestfulResult;
import com.xy.novelmanagement.service.ICommentManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/commentManagement")
public class CommentManagementController {
		@Autowired
		private ICommentManagementService commentManagementService;

		@GetMapping("/")
		public RestfulResult getList(Integer pageSize,Integer pageNum,String overTime){
				log.info("CommentManagementController getList pageSize : "+pageSize);
				log.info("CommentManagementController getList pageNum : "+pageNum);
				log.info("CommentManagementController getList overTime : "+overTime);
				PageList<Comment> commentList = commentManagementService.getCommentList(pageNum,pageSize,overTime);
				log.info("CommentManagementController getList commentList : "+commentList);
				return RestfulResult.success(commentList);
		}

		@DeleteMapping(value = "/",produces = "application/json;charset=UTF-8")
		public  RestfulResult deleteComments(@RequestBody List<Comment> commentList){
				log.info("CommentManagementController deleteComments commentList = " +commentList);
				if(commentList.size()<1){
						return RestfulResult.failed("400", "要删除的评论数不能为0；");
				}
				Integer restCode = commentManagementService.deleteComments(commentList);
				return RestfulResult.success(restCode);
		}
}
